<template>
  <div class="body">
    <div class="body-left">
      <div
        class="body-left-title"
        :class="active === item.active ? 'active' : ''"
        v-for="(item, index) in titleArr"
        :key="index"
        @click="handleClick(index)"
      >
        <Icon
          :title="item.title"
          :name="item.active"
          :fontSize="16"
          :color="
            active === item.active
              ? 'rgba(0, 210, 255, 1)'
              : 'rgba(167, 190, 202, 1)'
          "
        />
        <span>{{ item.title }}</span>
      </div>
    </div>
    <el-scrollbar class="body-right">
      <div
        v-if="
          active === 'jibenxinxi' && detailData !== null
        "
        class="body-right-container"
      >
        <el-scrollbar style="height: 100%">
          <label-value
            v-for="(val, key) in baseInformation"
            :label="key"
            :value="val"
            :key="key"
          />
        </el-scrollbar>
        <!--        <label-value-->
        <!--          label="项目编号："-->
        <!--          :value="detailData.code"-->
        <!--        />-->
        <!--        <label-value-->
        <!--          label="项目类型："-->
        <!--          :value="detailData.type"-->
        <!--        />-->
        <!--        <label-value-->
        <!--          label="项目状态："-->
        <!--          :value="detailData.status"-->
        <!--        />-->
        <!--        <label-value-->
        <!--          label="项目名称："-->
        <!--          :value="detailData.name"-->
        <!--        />-->
        <!--        <label-value-->
        <!--          label="建设规模："-->
        <!--          :value="detailData.scale"-->
        <!--        />-->
        <!--        <label-value-->
        <!--          label="建设周期："-->
        <!--          :value="detailData.cycle"-->
        <!--        />-->
        <!--        <label-value-->
        <!--          label="总投资(万元)："-->
        <!--          :value="detailData.amount"-->
        <!--        />-->
        <!--        <label-value-->
        <!--          label="资金来源："-->
        <!--          :value="detailData.capitalSource"-->
        <!--        />-->
        <!--        <label-value-->
        <!--          label="施工进度："-->
        <!--          :value="detailData.progress"-->
        <!--        />-->
        <!--        <label-value-->
        <!--          label="实施单位："-->
        <!--          :value="detailData.unit"-->
        <!--        />-->
        <!--        <label-value-->
        <!--          label="基本信息："-->
        <!--          :value="detailData.introduce"-->
        <!--        />-->
      </div>
      <div v-else-if="active === 'xiangmusheji'">
        <!--        <span>项目设计</span>-->
      </div>
      <div v-else-if="active === 'shigongjindu'">
        <!--        <span>施工进度</span>-->
      </div>
      <div v-else-if="active === 'jungongyanshou'">
        <!--        <span>竣工验收</span>-->
      </div>
    </el-scrollbar>
  </div>
</template>

<script>
import Icon from '@/components/icon'
import LabelValue from './labelValue'

export default {
  name: 'detail',
  components: {
    Icon,
    LabelValue
  },
  props: {
    detailData: {
      type: Object
    }
  },
  data() {
    return {
      active: 'jibenxinxi',
      titleArr: [
        {
          title: '基本信息',
          active: 'jibenxinxi'
        },
        {
          title: '项目设计',
          active: 'xiangmusheji'
        },
        {
          title: '施工进度',
          active: 'shigongjindu'
        },
        {
          title: '竣工验收',
          active: 'jungongyanshou'
        }
      ],
      baseInformation: {}
    }
  },
  methods: {
    handleClick(index) {
      this.active = this.titleArr[index].active
    }
  },
  watch: {
    detailData(val) {
      if (val && val.geojson) {
        try {
          const json = JSON.parse(
            val.geojson.replace('\n', '')
          )
          this.baseInformation = json.features[0].properties
        } catch (e) {
          this.baseInformation = {}
          console.error(e)
        }
      }
    }
  }
}
</script>

<style scoped lang="scss">
.body {
  width: 100%;
  height: 100%;
  display: flex;

  &-left {
    width: 116px;
    min-width: 100px;
    height: 100%;
    border-right: 1px solid #4e5f6a;

    &-title {
      width: 100%;
      height: 28px;
      display: flex;
      justify-content: center;
      align-items: center;

      &:nth-of-type(1) {
        margin-top: 10px;
      }

      &:not(:last-of-type) {
        margin-bottom: 10px;
      }

      span {
        font-size: 14px;
        font-weight: 400;
        margin-left: 3px;
        color: white;
      }

      &.active {
        background-image: url('~@/assets/img/project_info_item_bg.png');
        background-size: contain;
        background-repeat: no-repeat;

        span {
          color: #00d2ff;
        }
      }
    }
  }

  &-right {
    width: 450px;
    height: 100%;

    ::v-deep {
      .el-scrollbar {
        &__view {
          height: 100%;
        }
      }
    }

    &-container {
      height: 100%;
      display: flex;
      flex-direction: column;
      padding: 18px 13px;

      .label-value {
        display: flex;
        align-items: flex-start;

        &:not(:last-of-type) {
          margin-bottom: 13px;
        }
      }
    }
  }
}
</style>
